<?php

class Emms_Form_Loan_Application extends HTech_Form
{
    private $_maxFirstPaymentDate; 
    private $_loanProductParams; 
    private $_borrower;
    
    public function getBorrower()
    {
        return $this->_borrower;
    }
        
    public function getValues()
    {
        $d = array();
        $data = parent::getValues();
        
        $principalByClientId = array_diff_key($data['Principal'],array_flip($data['NoLoan']));
        $data['Principal'] = array_sum($principalByClientId);
        
        /*
         * $loan - Virtual loan representing all amounts requested,
         * used to figure it out tentative delivery and cancel dates
         * from posted fields
         */
        $loan = new Emms_Loan($data);
        
        $d['LoanMasterId'] = "";
        $d['ProductLineId'] = $data['ProductLineId'];
        $d['ProgramId'] = $data['ProgramId'];
        $d['LoanProductId'] = $data['LoanProductId'];
        $d['LocationId'] = $data['LocationId'];
        $d['OfficerUserId'] = $data['OfficerUserId'];
        $d['BorrowerType'] = $data['BorrowerType'];
        $d['BorrowerId'] = $data['BorrowerId'];
        $d['Status'] = "New";
        $d['CheckNumber'] = "";
        $d['Amount'] = $data['Principal'];
        $d['TentativeDeliveryDate'] = $data['TentativeDeliveryDate'];
        $d['TentativePrincipalGraceEndDate'] = $loan->getPrincipalGraceEndDate();
        $d['TentativeFirstPaymentDate'] = $data['TentativeFirstPaymentDate'];
        $d['TentativeCancelDate'] = $loan->getTentativeCancelDate();
        $d['LastEditDate'] = $data['LastEditDate'];
        $d['LastEditUserId'] = $data['LastEditUserId'];
        
        foreach($principalByClientId as $clientId => $principal) {
            $d['Loan'][$clientId]['LoanId'] = "";
            $d['Loan'][$clientId]['ClientId'] = $clientId;
            $d['Loan'][$clientId]['Status'] = "New";
            $d['Loan'][$clientId]['InterestCalculation'] = $data['InterestCalculation'];
            $d['Loan'][$clientId]['Installments'] = $data['Installments'];
            //$d['Loan'][$clientId]['EffectiveRate'] = "null";
            $d['Loan'][$clientId]['AnnualPercentageRate'] = $data['AnnualPercentageRate'];
            $d['Loan'][$clientId]['LoanInsurancePct'] = $data['LoanInsurancePct'];
            $d['Loan'][$clientId]['HealthInsurancePct'] = $data['HealthInsurancePct'];
            $d['Loan'][$clientId]['AdministrativeFeePct'] = $data['AdministrativeFeePct'];
            $d['Loan'][$clientId]['PrincipalGraceRate'] = $data['PrincipalGraceRate'];
            $d['Loan'][$clientId]['DelayGrace'] = $data['DelayGrace'];
            $d['Loan'][$clientId]['DelayPenaltyRate'] = $data['DelayPenaltyRate'];
            $d['Loan'][$clientId]['DelayPenaltyFixedCharge'] = $data['DelayPenaltyFixedCharge'];
            $d['Loan'][$clientId]['PaymentFrequency'] = $data['PaymentFrequency'];
            $d['Loan'][$clientId]['CalendarType'] = $data['CalendarType'];
            $d['Loan'][$clientId]['Principal'] = $principal;
            $d['Loan'][$clientId]['LoanInsuranceMnt'] = 0.01*$principal*$data['LoanInsurancePct'];
            $d['Loan'][$clientId]['HealthInsuranceMnt'] = 0.01*$principal*$data['HealthInsurancePct'];
            $d['Loan'][$clientId]['AdministrativeFeeMnt'] = 0.01*$principal*$data['AdministrativeFeePct'];
            //$d['Loan'][$clientId]['VoluntarySavings'] = "null";
            //$d['Loan'][$clientId]['MandatorySavings'] = "null";
            $d['Loan'][$clientId]['PaymentMnt'] = $loan->getPmt()*($principal/$data['Principal']);
            $d['Loan'][$clientId]['LastEditDate'] = $data['LastEditDate'];
            $d['Loan'][$clientId]['LastEditUserId'] = $data['LastEditUserId'];
        }
        
        return $d;
    }
    
    private function _setLoanProductParams()
    {
        if($this->_request->isPost()) {
            $products = new LoanProducts();
            try {
                $this->_loanProductParams = $products->getRecord((int) $this->_request->getParam('LoanProductId'))->d->toArray();
            } catch (Exception $e) {
                $e = $e;
            }
        }
    }
    
    private function _setMaxFirstPaymentDate()
    {
        if($this->_request->isPost()) {
            try {
                $this->_maxFirstPaymentDate = Emms_PmtPlan::getMaxFirstPaymentDate(
                    $this->_request->getPost('TentativeDeliveryDate'), 
                    $this->_request->getPost('PrincipalGraceMargin'), 
                    $this->_request->getPost('PaymentFrequency'));
            } catch (Exception $e) {
                $e = $e; 
            }
        }
    }
    
    private function _setBorrower()
    {
        $groupId = (int) $this->_request->getParam('group');
        $clientId =  (int) $this->_request->getParam('client');
        if (!($groupId xor $clientId)) {
            $e = new Exception($this->translate('Invalid client or group'));
            $this->deny($e);
        }
        $borrowers = $groupId ? new Groups() : new Clients();
        try {
            $this->_borrower = $borrowers->getLoanApplicationData($groupId + $clientId);  
        } catch (Exception $e) { 
            $this->deny($e);
        }
        if (!$this->_borrower->Community) {
            $e = new Exception($this->translate('Borrower community not set'));
            $this->deny($e);
        }
    }
    
    public function __construct() 
    {
        parent::__construct(); 
        $this->_setLoanProductParams();
        $this->_setMaxFirstPaymentDate(); 
        $this->_setBorrower();     
        
        $this->setName('Application');
        
        $this->setAttrib('title', $this->translate("New loan application form"));
        
        //$loanMasterId = new Zend_Form_Element_Hidden('LoanMasterId');
        
        $locationId = new Zend_Form_Element_Hidden('LocationId');
        $locationId->setValue($this->_borrower->LocationId);
        
        $officerUserId = new Zend_Form_Element_Hidden('OfficerUserId');
        $officerUserId->setValue($this->_borrower->OfficerUserId);
        
        $borrowerType = new Zend_Form_Element_Hidden('BorrowerType');
        $borrowerType->setValue($this->_borrower->BorrowerType);
        
        $borrowerId = new Zend_Form_Element_Hidden('BorrowerId');
        $borrowerId->setValue($this->_borrower->Code);
        
        foreach($this->_borrower->Clients as $client) {
            $kp[$client->ClientId] = new Zend_Form_Element_Text($client->ClientId);
            $kp[$client->ClientId]//->setLabel("")
                ->setRequired(true)
                ->addValidator('NotEmpty', true, array('messages' => $this->translate("Loan amount can't be empty")))
                ->addValidator('Regex', true, array(
                    'pattern' => '(^\d+(\.\d{2})?$)',
                    'messages' => $this->translate("Invalid loan amount")))
                ->addDecorator(new HTech_Form_Decorator_Bare())
                ->setBelongsTo('Principal');
            $noLoan['ClientId'.$client->ClientId] = new Zend_Form_Element_Checkbox('ClientId'.$client->ClientId);
            $noLoan['ClientId'.$client->ClientId]
                ->setCheckedValue($client->ClientId)
                ->addDecorator(new HTech_Form_Decorator_Bare())
                ->setBelongsTo('NoLoan');
        }
          
        $deliveryDate = new Zend_Form_Element_Text('TentativeDeliveryDate');
        $deliveryDate->setLabel("Disbursement date")
            ->setRequired(true)
            ->addPrefixPath('HTech_Validate', 'HTech/Validate', 'validate')
            ->addValidator('Date', true, array(
                'weekday' => true, 
                'maxDate' => $this->_request->getPost('TentativeFirstPaymentDate'),
                'messages' => array(
                    'msgWeekday' => $this->translate("Weekend dates not allowed"),
                    'msgMaxDateStrict' => $this->translate("Non valid date or date range"))));
        
        $firstPaymentDate = new Zend_Form_Element_Text('TentativeFirstPaymentDate');
        $firstPaymentDate->setLabel("First payment date")
            ->setRequired(true)
            ->addPrefixPath('HTech_Validate', 'HTech/Validate', 'validate')
            ->addValidator('Date', true, array(
                'weekday' => true, 
                'minDate' => $this->_request->getParam('TentativeDeliveryDate'),
                'messages' => array(
                    'msgWeekday' => $this->translate("Weekend dates not allowed"),
                    'msgMinDateStrict' => $this->translate("Non valid date or date range"))))
            ->addValidator('Callback', true, array(
                'callback' => array($this, 'checkGraceMarginCallback'),
                'messages' => sprintf($this->translate("Principal grace margin invalid or exceeded. Maximum allowed: %s"), $this->_maxFirstPaymentDate))); 
                        
        $productLineId = new Zend_Form_Element_Select('ProductLineId');
        $productLineId->setLabel("Product line")                
            ->setAttrib('size','3')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions($this->_db->fetchPairs('select ProductLineId, ProductLine from product_lines'));  
                                                
        $programId = new Zend_Form_Element_Select('ProgramId');
        $programId->setLabel("Program")                
            ->setAttrib('size','3')
            ->addValidator('Callback', true, array(
                'callback' => array($this, 'checkProgramCallback'),
                'messages' => $this->translate("Invalid program")))
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions($this->_db->fetchPairs(sprintf('select ProgramId, Program from programs where Status = "Active" and ProductLineId = %s order by Program', (int) $this->_request->getPost('ProductLineId'))));
                                                
        $loanProductId = new Zend_Form_Element_Select('LoanProductId');
        $loanProductId->setLabel("Loan product")                
            ->setAttrib('size','3')
            ->addValidator('Callback', true, array(
                'callback' => array($this, 'checkLoanProductCallback'),
                'messages' => $this->translate("Invalid loan product")))
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions($this->_db->fetchPairs('select LoanProductId, Name from loan_products'));  
        
        /*
         * Loan product rates
         */                  
        $annualPercentageRate = new Zend_Form_Element_Text('AnnualPercentageRate');
        $annualPercentageRate->setLabel("Annual pct. rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Annual pct. rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid annual pct. rate")))
            ->addValidator('Between', true, array(
                'min' => $this->_loanProductParams['AnnualPercentageRateMin'],
                'max' => $this->_loanProductParams['AnnualPercentageRateMax'],
                'inclusive' => true,
                'messages' => sprintf($this->translate("Valid range from %s to %s"), 
                        $this->_loanProductParams['AnnualPercentageRateMin'], 
                        $this->_loanProductParams['AnnualPercentageRateMax'])))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $annualPercentageRateMin = new Zend_Form_Element_Text('AnnualPercentageRateMin');
        $annualPercentageRateMin->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $annualPercentageRateMax = new Zend_Form_Element_Text('AnnualPercentageRateMax');
        $annualPercentageRateMax->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare()); 
        
        $loanInsurancePct = new Zend_Form_Element_Text('LoanInsurancePct');
        $loanInsurancePct->setLabel("Loan ins. pct.")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Loan ins. pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid loan ins. pct.")))
            ->addValidator('Between', true, array(
                'min' => $this->_loanProductParams['LoanInsurancePctMin'],
                'max' => $this->_loanProductParams['LoanInsurancePctMax'],
                'inclusive' => true,
                'messages' => sprintf($this->translate("Valid range from %s to %s"), 
                        $this->_loanProductParams['LoanInsurancePctMin'], 
                        $this->_loanProductParams['LoanInsurancePctMax'])))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $loanInsurancePctMin = new Zend_Form_Element_Text('LoanInsurancePctMin');
        $loanInsurancePctMin->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $loanInsurancePctMax = new Zend_Form_Element_Text('LoanInsurancePctMax');
        $loanInsurancePctMax->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $healthInsurancePct = new Zend_Form_Element_Text('HealthInsurancePct');
        $healthInsurancePct->setLabel("Health ins. pct.")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Health ins. pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid health ins. pct.")))
            ->addValidator('Between', true, array(
                'min' => $this->_loanProductParams['HealthInsurancePctMin'],
                'max' => $this->_loanProductParams['HealthInsurancePctMax'],
                'inclusive' => true,
                'messages' => sprintf($this->translate("Valid range from %s to %s"), 
                        $this->_loanProductParams['HealthInsurancePctMin'], 
                        $this->_loanProductParams['HealthInsurancePctMax'])))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $healthInsurancePctMin = new Zend_Form_Element_Text('HealthInsurancePctMin');
        $healthInsurancePctMin->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $healthInsurancePctMax = new Zend_Form_Element_Text('HealthInsurancePctMax');
        $healthInsurancePctMax->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $administrativeFeePct = new Zend_Form_Element_Text('AdministrativeFeePct');
        $administrativeFeePct->setLabel("Admin. fee pct.")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Admin. fee pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid admin. fee pct.")))
            ->addValidator('Between', true, array(
                'min' => $this->_loanProductParams['AdministrativeFeePctMin'],
                'max' => $this->_loanProductParams['AdministrativeFeePctMax'],
                'inclusive' => true,
                'messages' => sprintf($this->translate("Valid range from %s to %s"), 
                        $this->_loanProductParams['AdministrativeFeePctMin'], 
                        $this->_loanProductParams['AdministrativeFeePctMax'])))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $administrativeFeePctMin = new Zend_Form_Element_Text('AdministrativeFeePctMin');
        $administrativeFeePctMin->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $administrativeFeePctMax = new Zend_Form_Element_Text('AdministrativeFeePctMax');
        $administrativeFeePctMax->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $principalGraceRate = new Zend_Form_Element_Text('PrincipalGraceRate');
        $principalGraceRate->setLabel("Principal grace rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Principal grace rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid principal grace rate")))
            ->addValidator('Between', true, array(
                'min' => $this->_loanProductParams['PrincipalGraceRateMin'],
                'max' => $this->_loanProductParams['PrincipalGraceRateMax'],
                'inclusive' => true,
                'messages' => sprintf($this->translate("Valid range from %s to %s"), 
                        $this->_loanProductParams['PrincipalGraceRateMin'], 
                        $this->_loanProductParams['PrincipalGraceRateMax'])))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $principalGraceRateMin = new Zend_Form_Element_Text('PrincipalGraceRateMin');
        $principalGraceRateMin->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $principalGraceRateMax = new Zend_Form_Element_Text('PrincipalGraceRateMax');
        $principalGraceRateMax->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $delayPenaltyRate = new Zend_Form_Element_Text('DelayPenaltyRate');
        $delayPenaltyRate->setLabel("Daily delay rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Daily delay rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid daily delay rate")))
            ->addValidator('Between', true, array(
                'min' => $this->_loanProductParams['DelayPenaltyRateMin'],
                'max' => $this->_loanProductParams['DelayPenaltyRateMax'],
                'inclusive' => true,
                'messages' => sprintf($this->translate("Valid range from %s to %s"), 
                        $this->_loanProductParams['DelayPenaltyRateMin'], 
                        $this->_loanProductParams['DelayPenaltyRateMax'])))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $delayPenaltyRateMin = new Zend_Form_Element_Text('DelayPenaltyRateMin');
        $delayPenaltyRateMin->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $delayPenaltyRateMax = new Zend_Form_Element_Text('DelayPenaltyRateMax');
        $delayPenaltyRateMax->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $delayPenaltyFixedCharge = new Zend_Form_Element_Text('DelayPenaltyFixedCharge');
        $delayPenaltyFixedCharge->setLabel("Delay fixed charge")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Delay fixed charge can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid delay fixed charge")))
            ->addValidator('Between', true, array(
                'min' => $this->_loanProductParams['DelayPenaltyFixedChargeMin'],
                'max' => $this->_loanProductParams['DelayPenaltyFixedChargeMax'],
                'inclusive' => true,
                'messages' => sprintf($this->translate("Valid range from %s to %s"), 
                        $this->_loanProductParams['DelayPenaltyFixedChargeMin'], 
                        $this->_loanProductParams['DelayPenaltyFixedChargeMax'])))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $delayPenaltyFixedChargeMin = new Zend_Form_Element_Text('DelayPenaltyFixedChargeMin');
        $delayPenaltyFixedChargeMin->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $delayPenaltyFixedChargeMax = new Zend_Form_Element_Text('DelayPenaltyFixedChargeMax');
        $delayPenaltyFixedChargeMax->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->addDecorator(new HTech_Form_Decorator_Bare());
        
        $interestCalculation = new Zend_Form_Element_Text('InterestCalculation');
        $interestCalculation->setLabel("Interest type")
            ->setAttrib('readonly', 'true');
        
        $paymentFrequency = new Zend_Form_Element_Text('PaymentFrequency');
        $paymentFrequency->setLabel("Payment frequency")
            ->setAttrib('readonly', 'true');
        
        $installments = new Zend_Form_Element_Text('Installments');
        $installments->setLabel("Installments")
            ->setAttrib('readonly', 'true');
        
        $calendarType = new Zend_Form_Element_Text('CalendarType');
        $calendarType->setLabel("Calendar")
            ->setAttrib('readonly', 'true');
        
        $principalGraceMargin = new Zend_Form_Element_Text('PrincipalGraceMargin');
        $principalGraceMargin->setLabel("Principal grace margin")
            ->setAttrib('readonly', 'true');
        
        $delayGrace = new Zend_Form_Element_Text('DelayGrace');
        $delayGrace->setLabel("Delay grace")
            ->setAttrib('readonly', 'true');
                                
        $submit = new Zend_Form_Element_Submit('Submit');
        $submit->setLabel("Submit")
            ->addDecorator(new HTech_Form_Decorator_Button(array('type' => 'submit')));
                
        $this->addElements(array($deliveryDate, $firstPaymentDate, $productLineId, $programId, $loanProductId, 
            $annualPercentageRate, $annualPercentageRateMin, $annualPercentageRateMax, 
            $loanInsurancePctMin, $loanInsurancePct, $loanInsurancePctMax,
            $healthInsurancePctMin, $healthInsurancePct, $healthInsurancePctMax, 
            $administrativeFeePctMin, $administrativeFeePct, $administrativeFeePctMax, 
            $principalGraceRateMin, $principalGraceRate, $principalGraceRateMax,
            $delayPenaltyRateMin, $delayPenaltyRate, $delayPenaltyRateMax,
            $delayPenaltyFixedChargeMin, $delayPenaltyFixedCharge, $delayPenaltyFixedChargeMax,
            $interestCalculation, $paymentFrequency, $installments, $calendarType, $principalGraceMargin, $delayGrace,
            $locationId, $officerUserId, $borrowerType, $borrowerId,
            $submit) + $kp + $noLoan);
    }
    
    public function checkProgramCallback($newProgram, $args) 
    {
        if(!isset($args['ProductLineId'])) $args['ProductLineId'] = 0;
        $check = $this->_db->fetchPairs(sprintf('select ProgramId,ProductLineId from programs 
            where ProgramId = %s and ProductLineId = %s', $newProgram, $args['ProductLineId']));
        if(count($check) < 1) return false;
        return true;    
    }
    
    public function checkLoanProductCallback($newLoanProduct, $args) 
    {
        /*
        if(!isset($args['ProgramId'])) $args['ProgramId'] = 0;
        $check = $this->_db->fetchPairs(sprintf('select LoanProductId, ProgramId from loan_products 
            where LoanProductId = %s and ProgramId = %s', $newLoanProduct, $args['ProgramId']));
        if(count($check) < 1) return false;
         * 
         */
        return true;    
    }
    
    public function checkGraceMarginCallback($date, $args)
    {
        if(!Zend_Date::isDate($args['TentativeDeliveryDate'], 'YYYY-MM-DD')) return true;
        if($args['TentativeDeliveryDate']>=$date) return false;
        if(!isset($args['LoanProductId'])) return true;
        if($date > $this->_maxFirstPaymentDate) return false;
        return true;
    }  
    
    /**
     * Returns false if $date is hollidays, malformed or invalid. Return true otherwise.
     * 
     * @param type $date Format YYYY-MM-DD
     * @return boolean
     */
    public function checkHollidaysCallback($date)
    {
        try {
            $hollidays = Emms_Date::isHollidays($date);
        } catch (Exception $e) {
            $e = $e;
            $hollidays = true;
        }
        if($hollidays) return false;
        return true; 
    }  
}